home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / sasl / sasl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-27  |  48.7 KB  |  1,262 lines

  1. /* This is a proposed C API for support of SASL
  2.  *
  3.  *********************************IMPORTANT*******************************
  4.  * send email to chris.newman@innosoft.com and cyrus-bugs@andrew.cmu.edu *
  5.  * if you need to add new error codes, callback types, property values,  *
  6.  * etc.   It is important to keep the multiple implementations of this   *
  7.  * API from diverging.                                                   *
  8.  *********************************IMPORTANT*******************************
  9.  *
  10.  * Basic Type Summary:
  11.  *  sasl_conn_t       Context for a SASL connection negotiation
  12.  *  sasl_ssf_t        Security layer Strength Factor
  13.  *  sasl_callback_t   A typed client/server callback function and context
  14.  *  sasl_interact_t   A client interaction descriptor
  15.  *  sasl_secret_t     A client password
  16.  *  sasl_rand_t       Random data context structure
  17.  *  sasl_security_properties_t  An application's required security level
  18.  *
  19.  * Callbacks:
  20.  *  sasl_getopt_t     client/server: Get an option value
  21.  *  sasl_logmsg_t     client/server: Log message handler
  22.  *  sasl_getsimple_t  client: Get user/language list
  23.  *  sasl_getsecret_t  client: Get authentication secret
  24.  *  sasl_chalprompt_t client: Display challenge and prompt for response
  25.  *
  26.  * Server only Callbacks:
  27.  *  sasl_authorize_t             user authorization policy callback
  28.  *  sasl_getconfpath_t           get path to search for config file
  29.  *  sasl_server_userdb_checkpass check password and auxprops in userdb
  30.  *  sasl_server_userdb_setpass   set password in userdb
  31.  *  sasl_server_canon_user       canonicalize username routine
  32.  *
  33.  * Client/Server Function Summary:
  34.  *  sasl_done         Release all SASL global state
  35.  *  sasl_dispose      Connection done: Dispose of sasl_conn_t
  36.  *  sasl_getprop      Get property (e.g., user name, security layer info)
  37.  *  sasl_setprop      Set property (e.g., external ssf)
  38.  *  sasl_errdetail    Generate string from last error on connection
  39.  *  sasl_errstring    Translate sasl error code to a string
  40.  *  sasl_encode       Encode data to send using security layer
  41.  *  sasl_decode       Decode data received using security layer
  42.  *  
  43.  * Utility functions:
  44.  *  sasl_encode64     Encode data to send using MIME base64 encoding
  45.  *  sasl_decode64     Decode data received using MIME base64 encoding
  46.  *  sasl_erasebuffer  Erase a buffer
  47.  *
  48.  * Client Function Summary:
  49.  *  sasl_client_init  Load and initialize client plug-ins (call once)
  50.  *  sasl_client_new   Initialize client connection context: sasl_conn_t
  51.  *  sasl_client_start Select mechanism for connection
  52.  *  sasl_client_step  Perform one authentication step
  53.  *
  54.  * Server Function Summary
  55.  *  sasl_server_init  Load and initialize server plug-ins (call once)
  56.  *  sasl_server_new   Initialize server connection context: sasl_conn_t
  57.  *  sasl_listmech     Create list of available mechanisms
  58.  *  sasl_server_start Begin an authentication exchange
  59.  *  sasl_server_step  Perform one authentication exchange step
  60.  *  sasl_checkpass    Check a plaintext passphrase
  61.  *  sasl_checkapop    Check an APOP challenge/response (uses pseudo "APOP"
  62.  *                    mechanism similar to CRAM-MD5 mechanism; optional)
  63.  *  sasl_user_exists  Check if user exists
  64.  *  sasl_setpass      Change a password or add a user entry
  65.  *  sasl_auxprop_request  Request auxiliary properties
  66.  *  sasl_auxprop_getctx   Get auxiliary property context for connection
  67.  *  sasl_auxprop_store    Store a set of auxiliary properties
  68.  *
  69.  * Basic client model:
  70.  *  1. client calls sasl_client_init() at startup to load plug-ins
  71.  *  2. when connection formed, call sasl_client_new()
  72.  *  3. once list of supported mechanisms received from server, client
  73.  *     calls sasl_client_start().  goto 4a
  74.  *  4. client calls sasl_client_step()
  75.  * [4a. If SASL_INTERACT, fill in prompts and goto 4
  76.  *      -- doesn't happen if callbacks provided]
  77.  *  4b. If SASL error, goto 7 or 3
  78.  *  4c. If SASL_OK, continue or goto 6 if last server response was success
  79.  *  5. send message to server, wait for response
  80.  *  5a. On data or success with server response, goto 4
  81.  *  5b. On failure goto 7 or 3
  82.  *  5c. On success with no server response continue
  83.  *  6. continue with application protocol until connection closes
  84.  *     call sasl_getprop/sasl_encode/sasl_decode() if using security layer
  85.  *  7. call sasl_dispose(), may return to step 2
  86.  *  8. call sasl_done() when program terminates
  87.  *
  88.  * Basic Server model:
  89.  *  1. call sasl_server_init() at startup to load plug-ins
  90.  *  2. On connection, call sasl_server_new()
  91.  *  3. call sasl_listmech() and send list to client]
  92.  *  4. after client AUTH command, call sasl_server_start(), goto 5a
  93.  *  5. call sasl_server_step()
  94.  *  5a. If SASL_CONTINUE, output to client, wait response, repeat 5
  95.  *  5b. If SASL error, then goto 7
  96.  *  5c. If SASL_OK, move on
  97.  *  6. continue with application protocol until connection closes
  98.  *     call sasl_getprop to get username
  99.  *     call sasl_getprop/sasl_encode/sasl_decode() if using security layer
  100.  *  7. call sasl_dispose(), may return to step 2
  101.  *  8. call sasl_done() when program terminates
  102.  *
  103.  *************************************************
  104.  * IMPORTANT NOTE: server realms / username syntax
  105.  *
  106.  * If a user name contains a "@", then the rightmost "@" in the user name
  107.  * separates the account name from the realm in which this account is
  108.  * located.  A single server may support multiple realms.  If the
  109.  * server knows the realm at connection creation time (e.g., a server
  110.  * with multiple IP addresses tightly binds one address to a specific
  111.  * realm) then that realm must be passed in the user_realm field of
  112.  * the sasl_server_new call.  If user_realm is non-empty and an
  113.  * unqualified user name is supplied, then the canon_user facility is
  114.  * expected to append "@" and user_realm to the user name.  The canon_user
  115.  * facility may treat other characters such as "%" as equivalent to "@".
  116.  *
  117.  * If the server forbids the use of "@" in user names for other
  118.  * purposes, this simplifies security validation.
  119.  */
  120.  
  121. #ifndef SASL_H
  122. #define SASL_H 1
  123.  
  124. /* Keep in sync with win32/common.mak */
  125. #define SASL_VERSION_MAJOR 2
  126. #define SASL_VERSION_MINOR 1
  127. #define SASL_VERSION_STEP 22
  128.  
  129. /* A convenience macro: same as was defined in the OpenLDAP LDAPDB */
  130. #define SASL_VERSION_FULL ((SASL_VERSION_MAJOR << 16) |\
  131.       (SASL_VERSION_MINOR << 8) | SASL_VERSION_STEP)
  132.  
  133. #include "prop.h"
  134.  
  135. /*************
  136.  * Basic API *
  137.  *************/
  138.  
  139. /* SASL result codes: */
  140. #define SASL_CONTINUE    1   /* another step is needed in authentication */
  141. #define SASL_OK          0   /* successful result */
  142. #define SASL_FAIL       -1   /* generic failure */
  143. #define SASL_NOMEM      -2   /* memory shortage failure */
  144. #define SASL_BUFOVER    -3   /* overflowed buffer */
  145. #define SASL_NOMECH     -4   /* mechanism not supported */
  146. #define SASL_BADPROT    -5   /* bad protocol / cancel */
  147. #define SASL_NOTDONE    -6   /* can't request info until later in exchange */
  148. #define SASL_BADPARAM   -7   /* invalid parameter supplied */
  149. #define SASL_TRYAGAIN   -8   /* transient failure (e.g., weak key) */
  150. #define SASL_BADMAC    -9   /* integrity check failed */
  151. #define SASL_NOTINIT    -12  /* SASL library not initialized */
  152.                              /* -- client only codes -- */
  153. #define SASL_INTERACT    2   /* needs user interaction */
  154. #define SASL_BADSERV    -10  /* server failed mutual authentication step */
  155. #define SASL_WRONGMECH  -11  /* mechanism doesn't support requested feature */
  156.                              /* -- server only codes -- */
  157. #define SASL_BADAUTH    -13  /* authentication failure */
  158. #define SASL_NOAUTHZ    -14  /* authorization failure */
  159. #define SASL_TOOWEAK    -15  /* mechanism too weak for this user */
  160. #define SASL_ENCRYPT    -16  /* encryption needed to use mechanism */
  161. #define SASL_TRANS      -17  /* One time use of a plaintext password will
  162.                 enable requested mechanism for user */
  163. #define SASL_EXPIRED    -18  /* passphrase expired, has to be reset */
  164. #define SASL_DISABLED   -19  /* account disabled */
  165. #define SASL_NOUSER     -20  /* user not found */
  166. #define SASL_BADVERS    -23  /* version mismatch with plug-in */
  167. #define SASL_UNAVAIL    -24  /* remote authentication server unavailable */
  168. #define SASL_NOVERIFY   -26  /* user exists, but no verifier for user */
  169.                  /* -- codes for password setting -- */
  170. #define SASL_PWLOCK     -21  /* passphrase locked */
  171. #define SASL_NOCHANGE   -22  /* requested change was not needed */
  172. #define SASL_WEAKPASS   -27  /* passphrase is too weak for security policy */
  173. #define SASL_NOUSERPASS -28  /* user supplied passwords not permitted */
  174.  
  175. /* max size of a sasl mechanism name */
  176. #define SASL_MECHNAMEMAX 20
  177.  
  178. #ifdef _WIN32
  179. /* Define to have the same layout as a WSABUF */
  180. #ifndef STRUCT_IOVEC_DEFINED
  181. #define STRUCT_IOVEC_DEFINED 1
  182. struct iovec {
  183.     long iov_len;
  184.     char *iov_base;
  185. };
  186. #endif
  187. #else
  188. struct iovec;                     /* Defined in OS headers */
  189. #endif
  190.  
  191.  
  192. /* per-connection SASL negotiation state for client or server
  193.  */
  194. typedef struct sasl_conn sasl_conn_t;
  195.  
  196. /* Plain text password structure.
  197.  *  len is the length of the password, data is the text.
  198.  */
  199. typedef struct sasl_secret {
  200.     unsigned long len;
  201.     unsigned char data[1];        /* variable sized */
  202. } sasl_secret_t;
  203.  
  204. /* random data context structure
  205.  */
  206. typedef struct sasl_rand_s sasl_rand_t;
  207.  
  208. #ifdef __cplusplus
  209. extern "C" {
  210. #endif
  211.  
  212. /****************************
  213.  * Configure Basic Services *
  214.  ****************************/
  215.  
  216. /* the following functions are used to adjust how allocation and mutexes work
  217.  * they must be called before all other SASL functions:
  218.  */
  219.  
  220. /* memory allocation functions which may optionally be replaced:
  221.  */
  222. typedef void *sasl_malloc_t(unsigned long);
  223. typedef void *sasl_calloc_t(unsigned long, unsigned long);
  224. typedef void *sasl_realloc_t(void *, unsigned long);
  225. typedef void sasl_free_t(void *);
  226.  
  227. LIBSASL_API void sasl_set_alloc(sasl_malloc_t *,
  228.                 sasl_calloc_t *,
  229.                 sasl_realloc_t *,
  230.                 sasl_free_t *);
  231.  
  232. /* mutex functions which may optionally be replaced:
  233.  *  sasl_mutex_alloc allocates a mutex structure
  234.  *  sasl_mutex_lock blocks until mutex locked
  235.  *   returns -1 on deadlock or parameter error
  236.  *   returns 0 on success
  237.  *  sasl_mutex_unlock unlocks mutex if it's locked
  238.  *   returns -1 if not locked or parameter error
  239.  *   returns 0 on success
  240.  *  sasl_mutex_free frees a mutex structure
  241.  */
  242. typedef void *sasl_mutex_alloc_t(void);
  243. typedef int sasl_mutex_lock_t(void *mutex);
  244. typedef int sasl_mutex_unlock_t(void *mutex);
  245. typedef void sasl_mutex_free_t(void *mutex);
  246. LIBSASL_API void sasl_set_mutex(sasl_mutex_alloc_t *, sasl_mutex_lock_t *,
  247.                 sasl_mutex_unlock_t *, sasl_mutex_free_t *);
  248.  
  249. /*****************************
  250.  * Security preference types *
  251.  *****************************/
  252.  
  253. /* security layer strength factor -- an unsigned integer usable by the caller
  254.  *  to specify approximate security layer strength desired.  Roughly
  255.  *  correlated to effective key length for encryption.
  256.  * 0   = no protection
  257.  * 1   = integrity protection only
  258.  * 40  = 40-bit DES or 40-bit RC2/RC4
  259.  * 56  = DES
  260.  * 112 = triple-DES
  261.  * 128 = 128-bit RC2/RC4/BLOWFISH
  262.  * 256 = baseline AES
  263.  */
  264. typedef unsigned sasl_ssf_t;
  265.  
  266. /* usage flags provided to sasl_server_new and sasl_client_new:
  267.  */
  268. #define SASL_SUCCESS_DATA    0x0004 /* server supports data on success */
  269. #define SASL_NEED_PROXY      0x0008 /* require a mech that allows proxying */
  270.  
  271. /***************************
  272.  * Security Property Types *
  273.  ***************************/
  274.  
  275. /* Structure specifying the client or server's security policy
  276.  * and optional additional properties.
  277.  */
  278.  
  279. /* These are the various security flags apps can specify. */
  280. /* NOPLAINTEXT          -- don't permit mechanisms susceptible to simple
  281.  *                         passive attack (e.g., PLAIN, LOGIN)
  282.  * NOACTIVE             -- protection from active (non-dictionary) attacks
  283.  *                         during authentication exchange.
  284.  *                         Authenticates server.
  285.  * NODICTIONARY         -- don't permit mechanisms susceptible to passive
  286.  *                         dictionary attack
  287.  * FORWARD_SECRECY      -- require forward secrecy between sessions
  288.  *                         (breaking one won't help break next)
  289.  * NOANONYMOUS          -- don't permit mechanisms that allow anonymous login
  290.  * PASS_CREDENTIALS     -- require mechanisms which pass client
  291.  *               credentials, and allow mechanisms which can pass
  292.  *               credentials to do so
  293.  * MUTUAL_AUTH          -- require mechanisms which provide mutual
  294.  *               authentication
  295.  */
  296. #define SASL_SEC_NOPLAINTEXT      0x0001
  297. #define SASL_SEC_NOACTIVE         0x0002
  298. #define SASL_SEC_NODICTIONARY     0x0004
  299. #define SASL_SEC_FORWARD_SECRECY  0x0008
  300. #define SASL_SEC_NOANONYMOUS      0x0010
  301. #define SASL_SEC_PASS_CREDENTIALS 0x0020
  302. #define SASL_SEC_MUTUAL_AUTH      0x0040
  303. #define SASL_SEC_MAXIMUM          0x00FF
  304.  
  305. typedef struct sasl_security_properties 
  306.     /* security strength factor
  307.      *  min_ssf      = minimum acceptable final level
  308.      *  max_ssf      = maximum acceptable final level
  309.      */ 
  310.     sasl_ssf_t min_ssf;
  311.     sasl_ssf_t max_ssf;
  312.  
  313.     /* Maximum security layer receive buffer size.
  314.      *  0=security layer not supported
  315.      */
  316.     unsigned maxbufsize; 
  317.     
  318.     /* bitfield for attacks to protect against */
  319.     unsigned security_flags;
  320.  
  321.     /* NULL terminated array of additional property names, values */ 
  322.     const char **property_names;
  323.     const char **property_values;
  324. } sasl_security_properties_t; 
  325.  
  326. /******************
  327.  * Callback types *
  328.  ******************/
  329.  
  330. /*
  331.  * Extensible type for a client/server callbacks
  332.  *  id      -- identifies callback type
  333.  *  proc    -- procedure call arguments vary based on id
  334.  *  context -- context passed to procedure
  335.  */
  336. /* Note that any memory that is allocated by the callback needs to be
  337.  * freed by the application, be it via function call or interaction.
  338.  *
  339.  * It may be freed after sasl_*_step returns SASL_OK.  if the mechanism
  340.  * requires this information to persist (for a security layer, for example)
  341.  * it must maintain a private copy.
  342.  */
  343. typedef struct sasl_callback {
  344.     /* Identifies the type of the callback function.
  345.      * Mechanisms must ignore callbacks with id's they don't recognize.
  346.      */
  347.     unsigned long id;
  348.     int (*proc)();   /* Callback function.  Types of arguments vary by 'id' */
  349.     void *context;
  350. } sasl_callback_t;
  351.  
  352. /* callback ids & functions:
  353.  */
  354. #define SASL_CB_LIST_END   0  /* end of list */
  355.  
  356. /* option reading callback -- this allows a SASL configuration to be
  357.  *  encapsulated in the caller's configuration system.  Some implementations
  358.  *  may use default config file(s) if this is omitted.  Configuration items
  359.  *  may be plugin-specific and are arbitrary strings.
  360.  *
  361.  * inputs:
  362.  *  context     -- option context from callback record
  363.  *  plugin_name -- name of plugin (NULL = general SASL option)
  364.  *  option      -- name of option
  365.  * output:
  366.  *  result      -- set to result which persists until next getopt in
  367.  *                 same thread, unchanged if option not found
  368.  *  len         -- length of result (may be NULL)
  369.  * returns:
  370.  *  SASL_OK     -- no error
  371.  *  SASL_FAIL   -- error
  372.  */
  373. typedef int sasl_getopt_t(void *context, const char *plugin_name,
  374.               const char *option,
  375.               const char **result, unsigned *len);
  376. #define SASL_CB_GETOPT       1
  377.  
  378. /* Logging levels for use with the logging callback function. */
  379. #define SASL_LOG_NONE  0    /* don't log anything */
  380. #define SASL_LOG_ERR   1    /* log unusual errors (default) */
  381. #define SASL_LOG_FAIL  2    /* log all authentication failures */
  382. #define SASL_LOG_WARN  3    /* log non-fatal warnings */
  383. #define SASL_LOG_NOTE  4    /* more verbose than LOG_WARN */
  384. #define SASL_LOG_DEBUG 5    /* more verbose than LOG_NOTE */
  385. #define SASL_LOG_TRACE 6    /* traces of internal protocols */
  386. #define SASL_LOG_PASS  7    /* traces of internal protocols, including
  387.                  * passwords */
  388.  
  389. /* logging callback -- this allows plugins and the middleware to
  390.  *  log operations they perform.
  391.  * inputs:
  392.  *  context     -- logging context from the callback record
  393.  *  level       -- logging level; see above
  394.  *  message     -- message to log
  395.  * returns:
  396.  *  SASL_OK     -- no error
  397.  *  SASL_FAIL   -- error
  398.  */
  399. typedef int sasl_log_t(void *context,
  400.                int level,
  401.                const char *message);
  402. #define SASL_CB_LOG        2
  403.  
  404. /* getpath callback -- this allows applications to specify the
  405.  * colon-separated path to search for plugins (by default,
  406.  * taken from an implementation-specific location).
  407.  * inputs:
  408.  *  context     -- getpath context from the callback record
  409.  * outputs:
  410.  *  path    -- colon seperated path
  411.  * returns:
  412.  *  SASL_OK     -- no error
  413.  *  SASL_FAIL   -- error
  414.  */
  415. typedef int sasl_getpath_t(void *context,
  416.                const char **path);
  417.  
  418. #define SASL_CB_GETPATH        3
  419.  
  420. /* verify file callback -- this allows applications to check if they
  421.  * want SASL to use files, file by file.  This is intended to allow
  422.  * applications to sanity check the environment to make sure plugins
  423.  * or the configuration file can't be written to, etc.
  424.  * inputs: 
  425.  *  context     -- verifypath context from the callback record
  426.  *  file        -- full path to file to verify
  427.  *  type        -- type of file to verify (see below)
  428.  
  429.  * returns:
  430.  *  SASL_OK        -- no error (file can safely be used)
  431.  *  SASL_CONTINUE  -- continue WITHOUT using this file
  432.  *  SASL_FAIL      -- error 
  433.  */
  434.  
  435. /* these are the types of files libsasl will ask about */
  436. typedef enum {
  437.     SASL_VRFY_PLUGIN=0,        /* a DLL/shared library plug-in */
  438.     SASL_VRFY_CONF=1,        /* a configuration file */
  439.     SASL_VRFY_PASSWD=2,        /* a password storage file/db */
  440.     SASL_VRFY_OTHER=3        /* some other file */
  441. } sasl_verify_type_t;
  442.  
  443. typedef int sasl_verifyfile_t(void *context,
  444.                               const char *file, sasl_verify_type_t type);
  445. #define SASL_CB_VERIFYFILE  4
  446.  
  447. /* getconfpath callback -- this allows applications to specify the
  448.  * colon-separated path to search for config files (by default,
  449.  * taken from the SASL_CONF_PATH environment variable).
  450.  * inputs:
  451.  *  context     -- getconfpath context from the callback record
  452.  * outputs:
  453.  *  path        -- colon seperated path (allocated on the heap; the
  454.  *                 library will free it using the sasl_free_t *
  455.  *                 passed to sasl_set_callback, or the standard free()
  456.  *                 library call).
  457.  * returns:
  458.  *  SASL_OK     -- no error
  459.  *  SASL_FAIL   -- error
  460.  */
  461. typedef int sasl_getconfpath_t(void *context,
  462.                                char **path);
  463.  
  464. #define SASL_CB_GETCONFPATH  5
  465.  
  466. /* client/user interaction callbacks:
  467.  */
  468. /* Simple prompt -- result must persist until next call to getsimple on
  469.  *  same connection or until connection context is disposed
  470.  * inputs:
  471.  *  context       -- context from callback structure
  472.  *  id            -- callback id
  473.  * outputs:
  474.  *  result        -- set to NUL terminated string
  475.  *                   NULL = user cancel
  476.  *  len           -- length of result
  477.  * returns SASL_OK
  478.  */
  479. typedef int sasl_getsimple_t(void *context, int id,
  480.                  const char **result, unsigned *len);
  481. #define SASL_CB_USER         0x4001  /* client user identity to login as */
  482. #define SASL_CB_AUTHNAME     0x4002  /* client authentication name */
  483. #define SASL_CB_LANGUAGE     0x4003  /* comma separated list of RFC 1766
  484.                           * language codes in order of preference
  485.                       * to be used to localize client prompts
  486.                       * or server error codes */
  487. #define SASL_CB_CNONCE       0x4007  /* caller supplies client-nonce
  488.                       * primarily for testing purposes */
  489.  
  490. /* get a sasl_secret_t (plaintext password with length)
  491.  * inputs:
  492.  *  conn          -- connection context
  493.  *  context       -- context from callback structure
  494.  *  id            -- callback id
  495.  * outputs:
  496.  *  psecret       -- set to NULL to cancel
  497.  *                   set to password structure which must persist until
  498.  *                   next call to getsecret in same connection, but middleware
  499.  *                   will erase password data when it's done with it.
  500.  * returns SASL_OK
  501.  */
  502. typedef int sasl_getsecret_t(sasl_conn_t *conn, void *context, int id,
  503.                  sasl_secret_t **psecret);
  504. #define SASL_CB_PASS         0x4004  /* client passphrase-based secret */
  505.  
  506.  
  507. /* prompt for input in response to a challenge.
  508.  * input:
  509.  *  context   -- context from callback structure
  510.  *  id        -- callback id
  511.  *  challenge -- server challenge
  512.  * output:
  513.  *  result    -- NUL terminated result, NULL = user cancel
  514.  *  len       -- length of result
  515.  * returns SASL_OK
  516.  */
  517. typedef int sasl_chalprompt_t(void *context, int id,
  518.                   const char *challenge,
  519.                   const char *prompt, const char *defresult,
  520.                   const char **result, unsigned *len);
  521. #define SASL_CB_ECHOPROMPT   0x4005 /* challenge and client enterred result */
  522. #define SASL_CB_NOECHOPROMPT 0x4006 /* challenge and client enterred result */
  523.  
  524. /* prompt (or autoselect) the realm to do authentication in.
  525.  *  may get a list of valid realms.
  526.  * input:
  527.  *  context     -- context from callback structure
  528.  *  id          -- callback id
  529.  *  availrealms -- available realms; string list; NULL terminated
  530.  *                 list may be empty.
  531.  * output:
  532.  *  result      -- NUL terminated realm; NULL is equivalent to ""
  533.  * returns SASL_OK
  534.  * result must persist until the next callback
  535.  */
  536. typedef int sasl_getrealm_t(void *context, int id,
  537.                 const char **availrealms,
  538.                 const char **result);
  539. #define SASL_CB_GETREALM (0x4008) /* realm to attempt authentication in */
  540.  
  541. /* server callbacks:
  542.  */
  543.  
  544. /* improved callback to verify authorization;
  545.  *     canonicalization now handled elsewhere
  546.  *  conn           -- connection context
  547.  *  requested_user -- the identity/username to authorize (NUL terminated)
  548.  *  rlen           -- length of requested_user
  549.  *  auth_identity  -- the identity associated with the secret (NUL terminated)
  550.  *  alen           -- length of auth_identity
  551.  *  default_realm  -- default user realm, as passed to sasl_server_new if
  552.  *  urlen          -- length of default realm
  553.  *  propctx        -- auxiliary properties
  554.  * returns SASL_OK on success,
  555.  *         SASL_NOAUTHZ or other SASL response on failure
  556.  */
  557. typedef int sasl_authorize_t(sasl_conn_t *conn,
  558.                  void *context,
  559.                  const char *requested_user, unsigned rlen,
  560.                  const char *auth_identity, unsigned alen,
  561.                  const char *def_realm, unsigned urlen,
  562.                  struct propctx *propctx);
  563. #define SASL_CB_PROXY_POLICY 0x8001
  564.  
  565. /* functions for "userdb" based plugins to call to get/set passwords.
  566.  * the location for the passwords is determined by the caller or middleware.
  567.  * plug-ins may get passwords from other locations.
  568.  */
  569.  
  570. /* callback to verify a plaintext password against the caller-supplied
  571.  * user database.  This is necessary to allow additional <method>s for
  572.  * encoding of the userPassword property.
  573.  *  user          -- NUL terminated user name with user@realm syntax
  574.  *  pass          -- password to check (may not be NUL terminated)
  575.  *  passlen       -- length of password to check
  576.  *  propctx       -- auxiliary properties for user
  577.  */
  578. typedef int sasl_server_userdb_checkpass_t(sasl_conn_t *conn,
  579.                        void *context,
  580.                        const char *user,
  581.                        const char *pass,
  582.                        unsigned passlen,
  583.                        struct propctx *propctx);
  584. #define SASL_CB_SERVER_USERDB_CHECKPASS (0x8005)
  585.  
  586. /* callback to store/change a plaintext password in the user database
  587.  *  user          -- NUL terminated user name with user@realm syntax
  588.  *  pass          -- password to store (may not be NUL terminated)
  589.  *  passlen       -- length of password to store
  590.  *  propctx       -- auxiliary properties (not stored)
  591.  *  flags         -- see SASL_SET_* flags below (SASL_SET_CREATE optional)
  592.  */
  593. typedef int sasl_server_userdb_setpass_t(sasl_conn_t *conn,
  594.                      void *context,
  595.                      const char *user,
  596.                      const char *pass,
  597.                      unsigned passlen,
  598.                      struct propctx *propctx,
  599.                      unsigned flags);
  600. #define SASL_CB_SERVER_USERDB_SETPASS (0x8006)
  601.  
  602. /* callback for a server-supplied user canonicalization function.
  603.  *
  604.  * This function is called directly after the mechanism has the
  605.  * authentication and authorization IDs.  It is called before any
  606.  * User Canonicalization plugin is called.  It has the responsibility
  607.  * of copying its output into the provided output buffers.
  608.  * 
  609.  *  in, inlen     -- user name to canonicalize, may not be NUL terminated
  610.  *                   may be same buffer as out
  611.  *  flags         -- not currently used, supplied by auth mechanism
  612.  *  user_realm    -- the user realm (may be NULL in case of client)
  613.  *  out           -- buffer to copy user name
  614.  *  out_max       -- max length of user name
  615.  *  out_len       -- set to length of user name
  616.  *
  617.  * returns
  618.  *  SASL_OK         on success
  619.  *  SASL_BADPROT    username contains invalid character
  620.  */
  621.  
  622. /* User Canonicalization Function Flags */
  623.  
  624. #define SASL_CU_NONE    0x00 /* Not a valid flag to pass */
  625. /* One of the following two is required */
  626. #define SASL_CU_AUTHID  0x01
  627. #define SASL_CU_AUTHZID 0x02
  628.  
  629. typedef int sasl_canon_user_t(sasl_conn_t *conn,
  630.                   void *context,
  631.                   const char *in, unsigned inlen,
  632.                   unsigned flags,
  633.                   const char *user_realm,
  634.                   char *out,
  635.                   unsigned out_max, unsigned *out_len);
  636.  
  637. #define SASL_CB_CANON_USER (0x8007)
  638.  
  639. /**********************************
  640.  * Common Client/server functions *
  641.  **********************************/
  642.  
  643. /* Types of paths to set (see sasl_set_path below). */
  644. #define SASL_PATH_TYPE_PLUGIN    0
  645. #define SASL_PATH_TYPE_CONFIG    1
  646.  
  647. /* a simpler way to set plugin path or configuration file path
  648.  * without the need to set sasl_getpath_t callback.
  649.  *
  650.  * This function can be called before sasl_server_init/sasl_client_init.
  651.  */  
  652. LIBSASL_API int sasl_set_path (int path_type, char * path);
  653.  
  654. /* get sasl library version information
  655.  * implementation is a vendor-defined string
  656.  * version is a vender-defined representation of the version #.
  657.  *
  658.  * This function is being deprecated in favor of sasl_version_info. */
  659. LIBSASL_API void sasl_version(const char **implementation,
  660.                   int *version);
  661.  
  662. /* Extended version of sasl_version().
  663.  *
  664.  * This function is to be used
  665.  *  for library version display and logging
  666.  *  for bug workarounds in old library versions
  667.  *
  668.  * The sasl_version_info is not to be used for API feature detection.
  669.  *
  670.  * All parameters are optional. If NULL is specified, the value is not returned.
  671.  */
  672. LIBSASL_API void sasl_version_info (const char **implementation,
  673.                 const char **version_string,
  674.                 int *version_major,
  675.                 int *version_minor,
  676.                 int *version_step,
  677.                 int *version_patch);
  678.  
  679. /* dispose of all SASL plugins.  Connection
  680.  * states have to be disposed of before calling this.
  681.  */
  682. LIBSASL_API void sasl_done(void);
  683.  
  684. /* dispose connection state, sets it to NULL
  685.  *  checks for pointer to NULL
  686.  */
  687. LIBSASL_API void sasl_dispose(sasl_conn_t **pconn);
  688.  
  689. /* translate an error number into a string
  690.  * input:
  691.  *  saslerr  -- the error number
  692.  *  langlist -- comma separated list of RFC 1766 languages (may be NULL)
  693.  * results:
  694.  *  outlang  -- the language actually used (may be NULL if don't care)
  695.  * returns:
  696.  *  the error message in UTF-8 (only the US-ASCII subset if langlist is NULL)
  697.  */
  698. LIBSASL_API const char *sasl_errstring(int saslerr,
  699.                        const char *langlist,
  700.                        const char **outlang);
  701.  
  702. /* get detail about the last error that occurred on a connection
  703.  * text is sanitized so it's suitable to send over the wire
  704.  * (e.g., no distinction between SASL_BADAUTH and SASL_NOUSER)
  705.  * input:
  706.  *  conn          -- mandatory connection context
  707.  * returns:
  708.  *  the error message in UTF-8 (only the US-ASCII subset permitted if no
  709.  *  SASL_CB_LANGUAGE callback is present)
  710.  */
  711. LIBSASL_API const char *sasl_errdetail(sasl_conn_t *conn);
  712.  
  713. /* set the error string which will be returned by sasl_errdetail() using
  714.  *  syslog()-style formatting (e.g. printf-style with %m as most recent
  715.  *  errno error)
  716.  *
  717.  *  primarily for use by server callbacks such as the sasl_authorize_t
  718.  *  callback and internally to plug-ins
  719.  *
  720.  * This will also trigger a call to the SASL logging callback (if any)
  721.  * with a level of SASL_LOG_FAIL unless the SASL_NOLOG flag is set.
  722.  *
  723.  * Messages should be sensitive to the current language setting.  If there
  724.  * is no SASL_CB_LANGUAGE callback messages MUST be US-ASCII otherwise UTF-8
  725.  * is used and use of RFC 2482 for mixed-language text is encouraged.
  726.  *
  727.  * if conn is NULL, function does nothing
  728.  */
  729. LIBSASL_API void sasl_seterror(sasl_conn_t *conn, unsigned flags,
  730.                    const char *fmt, ...);
  731. #define SASL_NOLOG       0x01
  732.                
  733. /* get property from SASL connection state
  734.  *  propnum       -- property number
  735.  *  pvalue        -- pointer to value
  736.  * returns:
  737.  *  SASL_OK       -- no error
  738.  *  SASL_NOTDONE  -- property not available yet
  739.  *  SASL_BADPARAM -- bad property number
  740.  */
  741. LIBSASL_API int sasl_getprop(sasl_conn_t *conn, int propnum,
  742.                  const void **pvalue);
  743. #define SASL_USERNAME     0    /* pointer to NUL terminated user name */
  744. #define SASL_SSF          1    /* security layer security strength factor,
  745.                                  * if 0, call to sasl_encode, sasl_decode
  746.                                  * unnecessary */
  747. #define SASL_MAXOUTBUF    2     /* security layer max output buf unsigned */  
  748. #define SASL_DEFUSERREALM 3    /* default realm passed to server_new */
  749.                 /* or set with setprop */
  750. #define SASL_GETOPTCTX    4    /* context for getopt callback */
  751. #define SASL_CALLBACK     7    /* current callback function list */
  752. #define SASL_IPLOCALPORT  8    /* iplocalport string passed to server_new */
  753. #define SASL_IPREMOTEPORT 9    /* ipremoteport string passed to server_new */
  754.  
  755. /* This returns a string which is either empty or has an error message
  756.  * from sasl_seterror (e.g., from a plug-in or callback).  It differs
  757.  * from the result of sasl_errdetail() which also takes into account the
  758.  * last return status code.
  759.  */
  760. #define SASL_PLUGERR     10
  761.  
  762. /* a handle to any delegated credentials or NULL if none is present 
  763.  * is returned by the mechanism. The user will probably need to know
  764.  * which mechanism was used to actually known how to make use of them
  765.  * currently only implemented for the gssapi mechanism */
  766. #define SASL_DELEGATEDCREDS 11  
  767.  
  768. #define SASL_SERVICE      12    /* service passed to sasl_*_new */
  769. #define SASL_SERVERFQDN   13    /* serverFQDN passed to sasl_*_new */
  770. #define SASL_AUTHSOURCE   14    /* name of auth source last used, useful
  771.                  * for failed authentication tracking */
  772. #define SASL_MECHNAME     15    /* active mechanism name, if any */
  773. #define SASL_AUTHUSER     16    /* authentication/admin user */
  774. #define SASL_APPNAME      17    /* application name (used for logging/
  775.                    configuration), same as appname parameter
  776.                    to sasl_server_init */
  777.  
  778. /* GSS-API credential handle for sasl_client_step() or sasl_server_step().
  779.  * The application is responsible for releasing this credential handle. */
  780. #define    SASL_GSS_CREDS      18
  781.  
  782. /* GSS name (gss_name_t) of the peer, as output by gss_inquire_context()
  783.  * or gss_accept_sec_context().
  784.  * On server end this is similar to SASL_USERNAME, but the gss_name_t
  785.  * structure can contain additional attributes associated with the peer.
  786.  */
  787. #define    SASL_GSS_PEER_NAME    19
  788.  
  789. /* Local GSS name (gss_name_t) as output by gss_inquire_context(). This
  790.  * is particularly useful for servers that respond to multiple names. */
  791. #define    SASL_GSS_LOCAL_NAME    20
  792.  
  793.  
  794. /* set property in SASL connection state
  795.  * returns:
  796.  *  SASL_OK       -- value set
  797.  *  SASL_BADPARAM -- invalid property or value
  798.  */
  799. LIBSASL_API int sasl_setprop(sasl_conn_t *conn,
  800.                  int propnum,
  801.                  const void *value);
  802. #define SASL_SSF_EXTERNAL  100    /* external SSF active (sasl_ssf_t *) */
  803. #define SASL_SEC_PROPS     101    /* sasl_security_properties_t */
  804. #define SASL_AUTH_EXTERNAL 102    /* external authentication ID (const char *) */
  805.  
  806. /* If the SASL_AUTH_EXTERNAL value is non-NULL, then a special version of the
  807.  * EXTERNAL mechanism is enabled (one for server-embedded EXTERNAL mechanisms).
  808.  * Otherwise, the EXTERNAL mechanism will be absent unless a plug-in
  809.  * including EXTERNAL is present.
  810.  */
  811.  
  812. /* do precalculations during an idle period or network round trip
  813.  *  may pass NULL to precompute for some mechanisms prior to connect
  814.  *  returns 1 if action taken, 0 if no action taken
  815.  */
  816. LIBSASL_API int sasl_idle(sasl_conn_t *conn);
  817.  
  818. /**************
  819.  * Client API *
  820.  **************/
  821.  
  822. /* list of client interactions with user for caller to fill in
  823.  */
  824. typedef struct sasl_interact {
  825.     unsigned long id;        /* same as client/user callback ID */
  826.     const char *challenge;    /* presented to user (e.g. OTP challenge) */
  827.     const char *prompt;        /* presented to user (e.g. "Username: ") */
  828.     const char *defresult;    /* default result string */
  829.     const void *result;        /* set to point to result */
  830.     unsigned len;        /* set to length of result */
  831. } sasl_interact_t;
  832.  
  833. /* initialize the SASL client drivers
  834.  *  callbacks      -- base callbacks for all client connections;
  835.  *                    must include getopt callback
  836.  * returns:
  837.  *  SASL_OK        -- Success
  838.  *  SASL_NOMEM     -- Not enough memory
  839.  *  SASL_BADVERS   -- Mechanism version mismatch
  840.  *  SASL_BADPARAM  -- missing getopt callback or error in config file
  841.  *  SASL_NOMECH    -- No mechanisms available
  842.  *  ...
  843.  */
  844. LIBSASL_API int sasl_client_init(const sasl_callback_t *callbacks);
  845.  
  846. /* initialize a client exchange based on the specified mechanism
  847.  *  service       -- registered name of the service using SASL (e.g. "imap")
  848.  *  serverFQDN    -- the fully qualified domain name of the server
  849.  *  iplocalport   -- client IPv4/IPv6 domain literal string with port
  850.  *                    (if NULL, then mechanisms requiring IPaddr are disabled)
  851.  *  ipremoteport  -- server IPv4/IPv6 domain literal string with port
  852.  *                    (if NULL, then mechanisms requiring IPaddr are disabled)
  853.  *  prompt_supp   -- list of client interactions supported
  854.  *                   may also include sasl_getopt_t context & call
  855.  *                   NULL prompt_supp = user/pass via SASL_INTERACT only
  856.  *                   NULL proc = interaction supported via SASL_INTERACT
  857.  *  flags         -- server usage flags (see above)
  858.  * in/out:
  859.  *  pconn         -- connection negotiation structure
  860.  *                   pointer to NULL => allocate new
  861.  *
  862.  * Returns:
  863.  *  SASL_OK       -- success
  864.  *  SASL_NOMECH   -- no mechanism meets requested properties
  865.  *  SASL_NOMEM    -- not enough memory
  866.  */
  867. LIBSASL_API int sasl_client_new(const char *service,
  868.                 const char *serverFQDN,
  869.                 const char *iplocalport,
  870.                 const char *ipremoteport,
  871.                 const sasl_callback_t *prompt_supp,
  872.                 unsigned flags,
  873.                 sasl_conn_t **pconn);
  874.  
  875. /* select a mechanism for a connection
  876.  *  mechlist      -- mechanisms server has available (punctuation ignored)
  877.  *                   if NULL, then discard cached info and retry last mech
  878.  * output:
  879.  *  prompt_need   -- on SASL_INTERACT, list of prompts needed to continue
  880.  *                   may be NULL if callbacks provided
  881.  *  clientout     -- the initial client response to send to the server
  882.  *                   will be valid until next call to client_start/client_step
  883.  *                   NULL if mech doesn't include initial client challenge
  884.  *  mech          -- set to mechansm name of selected mechanism (may be NULL)
  885.  *
  886.  * Returns:
  887.  *  SASL_OK       -- success
  888.  *  SASL_NOMEM    -- not enough memory
  889.  *  SASL_NOMECH   -- no mechanism meets requested properties
  890.  *  SASL_INTERACT -- user interaction needed to fill in prompt_need list
  891.  */
  892. LIBSASL_API int sasl_client_start(sasl_conn_t *conn,
  893.                   const char *mechlist,
  894.                   sasl_interact_t **prompt_need,
  895.                   const char **clientout,
  896.                   unsigned *clientoutlen,
  897.                   const char **mech);
  898.  
  899. /* do a single authentication step.
  900.  *  serverin    -- the server message received by the client, MUST have a NUL
  901.  *                 sentinel, not counted by serverinlen
  902.  * output:
  903.  *  prompt_need -- on SASL_INTERACT, list of prompts needed to continue
  904.  *  clientout   -- the client response to send to the server
  905.  *                 will be valid until next call to client_start/client_step
  906.  *
  907.  * returns:
  908.  *  SASL_OK        -- success
  909.  *  SASL_INTERACT  -- user interaction needed to fill in prompt_need list
  910.  *  SASL_BADPROT   -- server protocol incorrect/cancelled
  911.  *  SASL_BADSERV   -- server failed mutual auth
  912.  */
  913. LIBSASL_API int sasl_client_step(sasl_conn_t *conn,
  914.                  const char *serverin,
  915.                  unsigned serverinlen,
  916.                  sasl_interact_t **prompt_need,
  917.                  const char **clientout,
  918.                  unsigned *clientoutlen);
  919.  
  920. /**************
  921.  * Server API *
  922.  **************/
  923.  
  924. /* initialize server drivers, done once per process
  925.  *  callbacks      -- callbacks for all server connections; must include
  926.  *                    getopt callback
  927.  *  appname        -- name of calling application (for lower level logging)
  928.  * results:
  929.  *  state          -- server state
  930.  * returns:
  931.  *  SASL_OK        -- success
  932.  *  SASL_BADPARAM  -- error in config file
  933.  *  SASL_NOMEM     -- memory failure
  934.  *  SASL_BADVERS   -- Mechanism version mismatch
  935.  */
  936. LIBSASL_API int sasl_server_init(const sasl_callback_t *callbacks,
  937.                  const char *appname);
  938.  
  939. /* IP/port syntax:
  940.  *  a.b.c.d;p              where a-d are 0-255 and p is 0-65535 port number.
  941.  *  e:f:g:h:i:j:k:l;p      where e-l are 0000-ffff lower-case hexidecimal
  942.  *  e:f:g:h:i:j:a.b.c.d;p  alternate syntax for previous
  943.  *
  944.  *  Note that one or more "0" fields in f-k can be replaced with "::"
  945.  *  Thus:                 e:f:0000:0000:0000:j:k:l;p
  946.  *  can be abbreviated:   e:f::j:k:l;p
  947.  *
  948.  * A buffer of size 52 is adequate for the longest format with NUL terminator.
  949.  */
  950.  
  951. /* create context for a single SASL connection
  952.  *  service        -- registered name of the service using SASL (e.g. "imap")
  953.  *  serverFQDN     -- Fully qualified domain name of server.  NULL means use
  954.  *                    gethostname() or equivalent.
  955.  *                    Useful for multi-homed servers.
  956.  *  user_realm     -- permits multiple user realms on server, NULL = default
  957.  *  iplocalport    -- server IPv4/IPv6 domain literal string with port
  958.  *                    (if NULL, then mechanisms requiring IPaddr are disabled)
  959.  *  ipremoteport   -- client IPv4/IPv6 domain literal string with port
  960.  *                    (if NULL, then mechanisms requiring IPaddr are disabled)
  961.  *  callbacks      -- callbacks (e.g., authorization, lang, new getopt context)
  962.  *  flags          -- usage flags (see above)
  963.  * returns:
  964.  *  pconn          -- new connection context
  965.  *
  966.  * returns:
  967.  *  SASL_OK        -- success
  968.  *  SASL_NOMEM     -- not enough memory
  969.  */
  970. LIBSASL_API int sasl_server_new(const char *service,
  971.                 const char *serverFQDN,
  972.                 const char *user_realm,
  973.                 const char *iplocalport,
  974.                 const char *ipremoteport,
  975.                 const sasl_callback_t *callbacks,
  976.                 unsigned flags,
  977.                 sasl_conn_t **pconn);
  978.  
  979. /* Return an array of NUL-terminated strings, terminated by a NULL pointer,
  980.  * which lists all possible mechanisms that the library can supply
  981.  *
  982.  * Returns NULL on failure. */
  983. LIBSASL_API const char ** sasl_global_listmech(void);
  984.  
  985. /* This returns a list of mechanisms in a NUL-terminated string
  986.  *  conn          -- the connection to list mechanisms for (either client
  987.  *                   or server)
  988.  *  user          -- restricts mechanisms to those available to that user
  989.  *                   (may be NULL, not used for client case)
  990.  *  prefix        -- appended to beginning of result
  991.  *  sep           -- appended between mechanisms
  992.  *  suffix        -- appended to end of result
  993.  * results:
  994.  *  result        -- NUL terminated result which persists until next
  995.  *                   call to sasl_listmech for this sasl_conn_t
  996.  *  plen          -- gets length of result (excluding NUL), may be NULL
  997.  *  pcount        -- gets number of mechanisms, may be NULL
  998.  *
  999.  * returns:
  1000.  *  SASL_OK        -- success
  1001.  *  SASL_NOMEM     -- not enough memory
  1002.  *  SASL_NOMECH    -- no enabled mechanisms
  1003.  */
  1004. LIBSASL_API int sasl_listmech(sasl_conn_t *conn,
  1005.                   const char *user,
  1006.                   const char *prefix,
  1007.                   const char *sep,
  1008.                   const char *suffix,
  1009.                   const char **result,
  1010.                   unsigned *plen,
  1011.                   int *pcount);
  1012.  
  1013. /* start a mechanism exchange within a connection context
  1014.  *  mech           -- the mechanism name client requested
  1015.  *  clientin       -- client initial response (NUL terminated), NULL if empty
  1016.  *  clientinlen    -- length of initial response
  1017.  *  serverout      -- initial server challenge, NULL if done 
  1018.  *                    (library handles freeing this string)
  1019.  *  serveroutlen   -- length of initial server challenge
  1020.  * output:
  1021.  *  pconn          -- the connection negotiation state on success
  1022.  *
  1023.  * Same returns as sasl_server_step() or
  1024.  * SASL_NOMECH if mechanism not available.
  1025.  */
  1026. LIBSASL_API int sasl_server_start(sasl_conn_t *conn,
  1027.                   const char *mech,
  1028.                   const char *clientin,
  1029.                   unsigned clientinlen,
  1030.                   const char **serverout,
  1031.                   unsigned *serveroutlen);
  1032.  
  1033. /* perform one step of the SASL exchange
  1034.  *  inputlen & input -- client data
  1035.  *                      NULL on first step if no optional client step
  1036.  *  outputlen & output -- set to the server data to transmit
  1037.  *                        to the client in the next step
  1038.  *                        (library handles freeing this)
  1039.  *
  1040.  * returns:
  1041.  *  SASL_OK        -- exchange is complete.
  1042.  *  SASL_CONTINUE  -- indicates another step is necessary.
  1043.  *  SASL_TRANS     -- entry for user exists, but not for mechanism
  1044.  *                    and transition is possible
  1045.  *  SASL_BADPARAM  -- service name needed
  1046.  *  SASL_BADPROT   -- invalid input from client
  1047.  *  ...
  1048.  */
  1049. LIBSASL_API int sasl_server_step(sasl_conn_t *conn,
  1050.                  const char *clientin,
  1051.                  unsigned clientinlen,
  1052.                  const char **serverout,
  1053.                  unsigned *serveroutlen);
  1054.  
  1055. /* check if an apop exchange is valid
  1056.  *  (note this is an optional part of the SASL API)
  1057.  *  if challenge is NULL, just check if APOP is enabled
  1058.  * inputs:
  1059.  *  challenge     -- challenge which was sent to client
  1060.  *  challen       -- length of challenge, 0 = strlen(challenge)
  1061.  *  response      -- client response, "<user> <digest>" (RFC 1939)
  1062.  *  resplen       -- length of response, 0 = strlen(response)
  1063.  * returns 
  1064.  *  SASL_OK       -- success
  1065.  *  SASL_BADAUTH  -- authentication failed
  1066.  *  SASL_BADPARAM -- missing challenge
  1067.  *  SASL_BADPROT  -- protocol error (e.g., response in wrong format)
  1068.  *  SASL_NOVERIFY -- user found, but no verifier
  1069.  *  SASL_NOMECH   -- mechanism not supported
  1070.  *  SASL_NOUSER   -- user not found
  1071.  */
  1072. LIBSASL_API int sasl_checkapop(sasl_conn_t *conn,
  1073.                    const char *challenge, unsigned challen,
  1074.                    const char *response, unsigned resplen);
  1075.  
  1076. /* check if a plaintext password is valid
  1077.  *   if user is NULL, check if plaintext passwords are enabled
  1078.  * inputs:
  1079.  *  user          -- user to query in current user_domain
  1080.  *  userlen       -- length of username, 0 = strlen(user)
  1081.  *  pass          -- plaintext password to check
  1082.  *  passlen       -- length of password, 0 = strlen(pass)
  1083.  * returns 
  1084.  *  SASL_OK       -- success
  1085.  *  SASL_NOMECH   -- mechanism not supported
  1086.  *  SASL_NOVERIFY -- user found, but no verifier
  1087.  *  SASL_NOUSER   -- user not found
  1088.  */
  1089. LIBSASL_API int sasl_checkpass(sasl_conn_t *conn,
  1090.                    const char *user, unsigned userlen,
  1091.                    const char *pass, unsigned passlen);
  1092.  
  1093. /* check if a user exists on server
  1094.  *  conn          -- connection context
  1095.  *  service       -- registered name of the service using SASL (e.g. "imap")
  1096.  *  user_realm    -- permits multiple user realms on server, NULL = default
  1097.  *  user          -- NUL terminated user name
  1098.  *
  1099.  * returns:
  1100.  *  SASL_OK       -- success
  1101.  *  SASL_DISABLED -- account disabled
  1102.  *  SASL_NOUSER   -- user not found
  1103.  *  SASL_NOVERIFY -- user found, but no usable mechanism
  1104.  *  SASL_NOMECH   -- no mechanisms enabled
  1105.  */
  1106. LIBSASL_API int sasl_user_exists(sasl_conn_t *conn,
  1107.                  const char *service,
  1108.                  const char *user_realm,
  1109.                  const char *user);
  1110.  
  1111. /* set the password for a user
  1112.  *  conn        -- SASL connection
  1113.  *  user        -- user name
  1114.  *  pass        -- plaintext password, may be NULL to remove user
  1115.  *  passlen     -- length of password, 0 = strlen(pass)
  1116.  *  oldpass     -- NULL will sometimes work
  1117.  *  oldpasslen  -- length of password, 0 = strlen(oldpass)
  1118.  *  flags       -- see flags below
  1119.  * 
  1120.  * returns:
  1121.  *  SASL_NOCHANGE  -- proper entry already exists
  1122.  *  SASL_NOMECH    -- no authdb supports password setting as configured
  1123.  *  SASL_NOVERIFY  -- user exists, but no settable password present
  1124.  *  SASL_DISABLED  -- account disabled
  1125.  *  SASL_PWLOCK    -- password locked
  1126.  *  SASL_WEAKPASS  -- password too weak for security policy
  1127.  *  SASL_NOUSERPASS -- user-supplied passwords not permitted
  1128.  *  SASL_FAIL      -- OS error
  1129.  *  SASL_BADPARAM  -- password too long
  1130.  *  SASL_OK        -- successful
  1131.  */
  1132. LIBSASL_API int sasl_setpass(sasl_conn_t *conn,
  1133.                  const char *user,
  1134.                  const char *pass, unsigned passlen,
  1135.                  const char *oldpass, unsigned oldpasslen,
  1136.                  unsigned flags);
  1137. #define SASL_SET_CREATE  0x01   /* create a new entry for user */
  1138. #define SASL_SET_DISABLE 0x02    /* disable user account */
  1139. #define SASL_SET_NOPLAIN 0x04    /* do not store secret in plain text */
  1140. #define SASL_SET_CURMECH_ONLY 0x08    /* set the mechanism specific password only.
  1141.                        fail if no current mechanism */
  1142.  
  1143. /*********************************************************
  1144.  * Auxiliary Property Support -- added by cjn 1999-09-29 *
  1145.  *********************************************************/
  1146.  
  1147. #define SASL_AUX_END      NULL    /* last auxiliary property */
  1148.  
  1149. /* traditional Posix items (should be implemented on Posix systems) */
  1150. #define SASL_AUX_PASSWORD_PROP "userPassword" /* User Password */
  1151. #define SASL_AUX_PASSWORD "*" SASL_AUX_PASSWORD_PROP /* User Password (of authid) */
  1152. #define SASL_AUX_UIDNUM   "uidNumber"    /* UID number for the user */
  1153. #define SASL_AUX_GIDNUM   "gidNumber"    /* GID for the user */
  1154. #define SASL_AUX_FULLNAME "gecos"    /* full name of the user, unix-style */
  1155. #define SASL_AUX_HOMEDIR  "homeDirectory" /* home directory for user */
  1156. #define SASL_AUX_SHELL    "loginShell"    /* login shell for the user */
  1157.  
  1158. /* optional additional items (not necessarily implemented) */
  1159. /* single preferred mail address for user canonically-quoted
  1160.  * RFC821/822 syntax */
  1161. #define SASL_AUX_MAILADDR "mail"
  1162. /* path to unix-style mailbox for user */
  1163. #define SASL_AUX_UNIXMBX  "mailMessageStore"
  1164. /* SMTP mail channel name to use if user authenticates successfully */
  1165. #define SASL_AUX_MAILCHAN "mailSMTPSubmitChannel"
  1166.  
  1167. /* Request a set of auxiliary properties
  1168.  *  conn         connection context
  1169.  *  propnames    list of auxiliary property names to request ending with
  1170.  *               NULL.  
  1171.  *
  1172.  * Subsequent calls will add items to the request list.  Call with NULL
  1173.  * to clear the request list.
  1174.  *
  1175.  * errors
  1176.  *  SASL_OK       -- success
  1177.  *  SASL_BADPARAM -- bad count/conn parameter
  1178.  *  SASL_NOMEM    -- out of memory
  1179.  */
  1180. LIBSASL_API int sasl_auxprop_request(sasl_conn_t *conn,
  1181.                      const char **propnames);
  1182.  
  1183. /* Returns current auxiliary property context.
  1184.  * Use functions in prop.h to access content
  1185.  *
  1186.  *  if authentication hasn't completed, property values may be empty/NULL
  1187.  *
  1188.  *  properties not recognized by active plug-ins will be left empty/NULL
  1189.  *
  1190.  *  returns NULL if conn is invalid.
  1191.  */
  1192. LIBSASL_API struct propctx *sasl_auxprop_getctx(sasl_conn_t *conn);
  1193.  
  1194. /* Store the set of auxiliary properties for the given user.
  1195.  * Use functions in prop.h to set the content.
  1196.  *
  1197.  *  conn         connection context
  1198.  *  ctx          property context from prop_new()/prop_request()/prop_set()
  1199.  *  user         NUL terminated user
  1200.  *
  1201.  * Call with NULL 'ctx' to see if the backend allows storing properties.
  1202.  *
  1203.  * errors
  1204.  *  SASL_OK       -- success
  1205.  *  SASL_NOMECH   -- can not store some/all properties
  1206.  *  SASL_BADPARAM -- bad conn/ctx/user parameter
  1207.  *  SASL_NOMEM    -- out of memory
  1208.  *  SASL_FAIL     -- failed to store
  1209.  */
  1210. LIBSASL_API int sasl_auxprop_store(sasl_conn_t *conn,
  1211.                    struct propctx *ctx, const char *user);
  1212.  
  1213. /**********************
  1214.  * security layer API *
  1215.  **********************/
  1216.  
  1217. /* encode a block of data for transmission using security layer,
  1218.  *  returning the input buffer if there is no security layer.
  1219.  *  output is only valid until next call to sasl_encode or sasl_encodev
  1220.  * returns:
  1221.  *  SASL_OK      -- success (returns input if no layer negotiated)
  1222.  *  SASL_NOTDONE -- security layer negotiation not finished
  1223.  *  SASL_BADPARAM -- inputlen is greater than the SASL_MAXOUTBUF
  1224.  */
  1225. LIBSASL_API int sasl_encode(sasl_conn_t *conn,
  1226.                 const char *input, unsigned inputlen,
  1227.                 const char **output, unsigned *outputlen);
  1228.  
  1229. /* encode a block of data for transmission using security layer
  1230.  *  output is only valid until next call to sasl_encode or sasl_encodev
  1231.  * returns:
  1232.  *  SASL_OK      -- success (returns input if no layer negotiated)
  1233.  *  SASL_NOTDONE -- security layer negotiation not finished
  1234.  *  SASL_BADPARAM -- input length is greater than the SASL_MAXOUTBUF
  1235.  *             or no security layer
  1236.  */
  1237. LIBSASL_API int sasl_encodev(sasl_conn_t *conn,
  1238.                  const struct iovec *invec, unsigned numiov,
  1239.                  const char **output, unsigned *outputlen);
  1240.  
  1241. /* decode a block of data received using security layer
  1242.  *  returning the input buffer if there is no security layer.
  1243.  *  output is only valid until next call to sasl_decode
  1244.  *
  1245.  *  if outputlen is 0 on return, than the value of output is undefined.
  1246.  *  
  1247.  * returns:
  1248.  *  SASL_OK      -- success (returns input if no layer negotiated)
  1249.  *  SASL_NOTDONE -- security layer negotiation not finished
  1250.  *  SASL_BADMAC  -- bad message integrity check
  1251.  */
  1252. LIBSASL_API int sasl_decode(sasl_conn_t *conn,
  1253.                 const char *input, unsigned inputlen,
  1254.                 const char **output, unsigned *outputlen);
  1255.  
  1256. #ifdef __cplusplus
  1257. }
  1258. #endif
  1259.  
  1260. #endif /* SASL_H */
  1261.